home *** CD-ROM | disk | FTP | other *** search
- /* Copyright © 1995-1996 : David Atkinson */
- /* V1.21 Sysanim.c */
- /* Calgor */
-
- #include<stdio.h>
- #include<stdlib.h>
- #include<signal.h>
- #include<string.h>
- #include<hold/extra.h>
- #include<intuition/intuition.h>
- #include<exec/types.h>
- #include<graphics/gfxbase.h>
- #include<graphics/gfxmacros.h>
- #include<graphics/sprite.h>
- #include<clib/exec_protos.h>
- #include<clib/wb_protos.h>
- #include<clib/graphics_protos.h>
- #include<clib/dos_protos.h>
- #include<clib/exec_protos.h>
- #include<clib/intuition_protos.h>
-
- #ifdef(V3)
- #endif
-
- typedef struct RastPort * RASTPTR;
- typedef struct SimpleSprite * SSPTR;
-
- extern void look_buf(char *[], int);
- extern void handler(int);
- extern void alert(char *);
- extern void copy_object(int,long,long,struct BitMap *);
- extern itochar(int, char []);
- extern void whatisit(char *);
- extern void al_clean(void);
- extern char check_index(char *);
- extern void get_road(PLAN);
- extern int putback(char *,int,VALUE);
- extern PLAN get_splan(int);
- extern void plan_clear(PLAN);
- extern SHORT anim_button(void);
- extern void back_drop(void);
- extern void shutdown(void);
- extern void clearkeybuf(void);
- extern void show_display(int);
-
- extern struct Library *GfxBase;
- extern struct TextFont *cfontptr;
- extern char *display;
- extern char *text[LISTMAX];
- extern struct RastPort sec_rastport;
- extern struct ViewPort sec_viewport;
- extern struct View sec_view, *old_view;
- extern int stop;
- extern struct Window *my_window;
- extern struct Screen *my_screen;
- extern SHORT squeek[2];
- extern BOOL keypress;
- extern BOOL lmbpress;
- extern BOOL wactive;
- extern struct BitMap sec_bitmap;
- extern VARBUILD argument[ARGNUM];
- extern ordersum[ARGNUM];
- extern int realindex;
- extern int dem_num;
- extern MAPDEM pathone[9];
- extern MAPDEM pathtwo[4];
- extern MAPDEM paththree[7];
- extern MAPDEM pathfour[3];
- extern MAPDEM pathfive[3];
- extern MAPDEM backone[4];
- extern ARECT Bplay;
- extern ARECT Bpause;
- extern ARECT Bffor;
- extern char editor[MAXCHARPATH];
- extern char choices[NUMOFOPT][SLENGTH];
- extern int old_dem;
-
- void draw_modes(UBYTE, RASTPTR, long, long, UBYTE);
- void scrollup(void);
- void scrolldown(void);
- void writetxt(int,int,RASTPTR,char *);
- void writeline(char *,int);
- void linehl_on(void);
- void linehl_off(void);
- void compare_line(void);
- void go_code(int);
- void wowboy(void);
- void play_col(int);
- void pause_col(int);
- void ff_col(int);
- void clr_dem(void);
- void clr_compare(void);
- void indicator_clr(void);
- void clr_code(void);
- void clean_local(void);
- void speed(void);
- void forward_move(MAPDEM [], MAPDEM, MAPDEM, SSPTR tech);
- void backward_move(MAPDEM [], MAPDEM, MAPDEM, SSPTR tech);
- void change_col(short);
- void reset_sprites(void);
- void set_sprite(void);
- void killsprite(void);
- void comp_wrt(int ,char *);
- void comp_scroll(void);
- PLAN get_dest(char *);
- int get_src(char *);
- void question(char *);
- int calc(int, char, int);
- void put_road(PLAN);
- void chk_view(struct View *,struct View *);
- void engrave_iray(int,int,int);
- void engrave_int(int);
- void chill(int);
-
- struct GfxBase *ps=NULL;
-
- UWORD apat = { 0xFFFF };
-
- char *raylist[RECUREDEPTH];
- FUNC func_index[FUNCMAX];
- PLAN array_map[ARRAYMAX][MEMMAX];
- PLAN dis_map[LEVEL][MAXACROSS];
- PLAN ic_map[FUNCMAX][VARMAX];
-
- WORD rect[10]=
- {
- 415,435,
- 627,435,
- 627,505,
- 415,505,
- 415,435
- };
-
- __aligned __chip UWORD pulse_data[10]=
- {
- 0x0000,0x0000,
- 0xE000,0x0000,
- 0xE000,0x0000,
- 0xE000,0x0000,
- 0x0000,0x0000
- };
-
- /* Image Data */
-
- __aligned __chip UWORD cart_data[34] = {
- 0x0000,0x0000,
- 0x0000,0xFFFF,
- 0x7FFE,0xFFFF,
- 0x7FFE,0xFFFF,
- 0x7FFE,0xFFFF,
- 0x7FFE,0xFFFF,
- 0x7FFE,0xFFFF,
- 0x7FFE,0xFFFF,
- 0x7FFE,0xFFFF,
- 0x7FFE,0xFFFF,
- 0x0000,0xFFFF,
- 0x0000,0x381C,
- 0x381C,0x542A,
- 0x381C,0x6C36,
- 0x381C,0x542A,
- 0x0000,0x381C,
- 0x0000,0x0000
- };
-
-
- __aligned __chip struct SimpleSprite pulse_sprite=
- {
- pulse_data,
- 3,
- 290, 24,
- 4
- };
-
- __aligned __chip struct SimpleSprite cart_sprite=
- {
- cart_data,
- 15,
- 22, 318,
- 6
- };
-
-
-
- BOOL locktwo = FALSE; /* Second lock off-on for test display */
- int icnum=0; /* Current array index */
- int pushn=0; /* Depth of name list stack */
- int fnum=-1; /* Function number currently being accessed */
- int raynum=-1; /* Array Currently Being Accesed */
- int ref=0; /* Reference point for code display scrolling */
- /* int mid=0; Reference point for array display V.121 */
- BOOL lock=FALSE; /* Lock off-on 0-1*/
- int pause=0; /* Pause off-on */
- SHORT play = 0; /* Play off-on */
- int dtype = 0; /* Current type of data structure being excessed */
- int types = 0; /* Old type of data structure */
- int let_across = 0; /* Number of spaces to begining */
- char back_name[MAXILEN];
- int back_x = 0;
- SHORT trip=1; /* Used in timing sprite scrolling*/
- SHORT fraction=1; /* Used in timing sprite scrolling */
- struct MsgPort *aport=NULL; /* Message Port for appmenu items */
-
-
- void chill(int secs){
- SHORT timer;
-
- for(timer=0;timer<secs;timer++){
- if(stop==0){
- wowboy();
- Delay(10);
- }
- }
- }
-
- /* Draw_modes - Sets the appropriate Pens and drawing modes */
- /* draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1); Standard */
-
- void draw_modes(UBYTE mask,RASTPTR rport,long col1,long col2,UBYTE mod)
- {
- SetWrMsk(rport,mask)
- SetAPen(rport,col1);
- SetBPen(rport,col2);
- SetOPen(rport,col1);
- SetAfPt(rport,&apat,0);
- SetDrMd(rport,mod);
- }
-
-
- /* Showcode - Displays the first five lines */
-
- void showcode(void)
- {
- int maxw=0;
- int y;
-
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- SetFont(&sec_rastport,cfontptr);
- for(y=5;y<MAXLINE;y++){
- if(text[y-5]){
- maxw=strlen(text[y-5]);
- if(maxw>CODEWIDTH)
- maxw = CODEWIDTH;
- Move(&sec_rastport,292,(55+(SPACE*y)) );
- Text(&sec_rastport,text[y-5],maxw);
- }
- }
- }
-
- /* Writetxt - Writes the given text at the given x and y */
-
- void writetxt(int rank, int file, RASTPTR lilt,char *letters)
- {
- if(letters!=NULL){
- SetFont(lilt,cfontptr);
- Move(lilt,rank,file);
- if(letters!=NULL)
- Text(lilt,letters,strlen(letters));
- }
- }
-
- /* Writeline - Writes one line of text (code player) */
-
- void writeline(char *passage,int linenum){
- int maxl=0;
-
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- SetFont(&sec_rastport,cfontptr);
- Move(&sec_rastport,292,(55+(SPACE*linenum)) );
- if(passage){
- maxl=strlen(passage);
- if(maxl>CODEWIDTH)
- maxl=CODEWIDTH;
- Text(&sec_rastport,passage,maxl);
- }
- }
-
- /* Scrolls text up one line (cp), switching off highlight first
- And replaces with a line at the bottom */
-
- void scrollup(void){
-
- char *tail;
-
- wowboy();
- if(stop==0){
- if ( (ref+7<LISTMAX) ){
- linehl_off();
- SetBPen(&sec_rastport,A_LLGREY);
- ScrollRaster(&sec_rastport,0,UP,282,47,619,178);
- ref++;
- tail=text[6+ref];
- writeline(tail,11);
- }
- }
- }
-
- /* Scrolls text down in code player, first switching highlight off */
-
- void scrolldown(void){
-
- char *head;
-
- wowboy();
- if(stop==0){
- if ( (ref-1)>=0 ) {
- linehl_off();
- ref--;
- SetBPen(&sec_rastport,A_LLGREY);
- ScrollRaster(&sec_rastport,0,DOWN,282,47,619,178);
- }
- if( (ref-5)>=0 ){
- head=text[ref-5];
- writeline(head,0);
- }
- }
- }
-
- /* Switches highlight on (code player) */
-
- void linehl_on(void){
-
- if(lock!=TRUE){
- draw_modes(0xFD,&sec_rastport,A_ORANGE,A_BLACK,COMPLEMENT);
- RectFill(&sec_rastport,282,102,619,113);
- SetWrMsk(&sec_rastport,0xFF);
- lock=TRUE;
- }
- }
-
- /* Switches highlight off (code player) */
-
- void linehl_off(void){
-
- if(lock!=FALSE){
- draw_modes(0xFD,&sec_rastport,A_LLGREY,A_BLACK,COMPLEMENT);
- RectFill(&sec_rastport,282,102,619,113);
- SetWrMsk(&sec_rastport,0xFF);
- lock=FALSE;
- }
- }
-
- /* Highlight on-off switch for the test gadget */
-
- void compare_line(void){
-
- if(locktwo != TRUE){
- draw_modes(0xFD,&sec_rastport,A_ORANGE,A_BLACK,COMPLEMENT);
- locktwo = TRUE;
- }
- else{
- draw_modes(0xFD,&sec_rastport,A_LLGREY,A_BLACK,COMPLEMENT);
- locktwo = FALSE;
- }
- RectFill(&sec_rastport,62,160,275,171);
- SetWrMsk(&sec_rastport,0xFF);
- }
-
-
- /* go_code is a major function, takes an integer which is the referance
- line number and scrolls code display to that line.
- Activating highlight when finished */
-
- void go_code(int level){
-
- int line_move;
- int ryth;
-
- line_move=ref-level; /* Uses a reference level to calculate up-down */
- if (line_move<0){
- for(ryth=0;ryth>line_move;ryth--){
- scrollup();
- if(stop==0){
- linehl_on(); /* Switches individual line segments on */
- chill( (STILL/5) / fraction);
- linehl_off();
- }
- }
- }
- if (line_move>0){
- for(ryth=0;ryth<line_move;ryth++){
- scrolldown();
- if(stop==0){
- linehl_on();
- chill( (STILL/5) / fraction);
- linehl_off();
- }
- }
- }
- linehl_on();
- wowboy();
- chill((STILL/2)/fraction);
- }
-
- /* chk_view takes the present view and the view you want, if they
- are different then assume that someone is looking at a different
- screen therefore save sprites last position and get rid. Then wait
- and let user get on with other things without taking up CPU cycles,
- hopefully. When my window is activated restore sprites
- and restore screen. */
-
- void chk_view(struct View *present, struct View *actual){
- MAPDEM pixie, imp;
- struct AppMenuItem *appitem=NULL;
- struct AppMessage *appmsg=NULL;
-
- if (actual!=present){
- if(actual==&sec_view){
- pixie.way = imp.way = (WORD) NULL;
- pixie.x = pulse_sprite.x;
- pixie.y = pulse_sprite.y;
- imp.x = cart_sprite.x;
- imp.y = cart_sprite.y;
- killsprite();
- }
- appitem=AddAppMenuItemA(0L,(ULONG) NULL,"Restore_Calgor",aport,(struct TagItem *) NULL);
- if(appitem){
- shutdown(); /* Close Screen and Window */
- WaitPort(aport);
- while( appmsg = (struct AppMessage *) GetMsg(aport) ){
- /* Don't have to do anything with it except reply back */
- ReplyMsg( (struct Message *) appmsg);
- }
- RemoveAppMenuItem(appitem);
- back_drop(); /* Open Screen and Window */
- }
- else{
- clean_local();
- alert("Failed To Add AppMenu (chk_view) \n");
- }
- if(actual==&sec_view){
- set_sprite();
- MoveSprite(&sec_viewport,&pulse_sprite,pixie.x,pixie.y);
- MoveSprite(&sec_viewport,&cart_sprite,imp.x,imp.y);
- }
- LoadView(actual);
- }
- }
-
-
- void wowboy(void){
- SHORT received = 0;
- ULONG lok;
- char filepath[MAXCHARPATH];
-
- if(stop==0){
- do {
- lok = LockIBase(0);
- ps = (struct GfxBase *) GfxBase;
- UnlockIBase(lok);
- chk_view(ps->ActiView,&sec_view);
- raise(SIGINT);
- if( (lmbpress==TRUE) || (keypress==TRUE) ){
- received = anim_button();
- clearkeybuf();
- switch(received){
- case PLAYBUT : case NUM1KEY :
- /* PLAY */
- stop=pause=0;
- pause_col(0);
- trip=fraction=1;
- play_col(1);
- ff_col(0);
- break;
- case FFORBUT : case NUM2KEY :
- /* FAST FORWARD */
- if( (pause!=1) && (play == 1) ){
- ff_col(1);
- fraction +=4;
- if(fraction>1000)
- fraction=1000;
- trip = 1;
- }
- break;
- case PAUSEBUT : case NUM3KEY :
- /* PAUSE */
- pause=1;
- pause_col(1);
- play_col(0);
- ff_col(0);
- break;
- case STOPBUT : case NUM4KEY :
- /* STOP */
- dem_num=100;
- pause=0;
- pause_col(0);
- play_col(0);
- ff_col(0);
- stop=1;
- fraction=1000;
- trip = 1200;
- break;
- case NOBUT :
- break;
- case EJECTBUT : case ESCKEY :
- pause=0;
- pause_col(0);
- play_col(0);
- ff_col(0);
- stop=1;
- fraction=1000;
- trip = 1200;
- break;
- case INFOBUT : case NUM5KEY :
- /* INFORMATION BUTTON */
- if(pause==1){
- killsprite();
- shutdown();
- LoadView(old_view);
- strcpy(filepath,editor);
- strcat(filepath," ");
- strcat(filepath,ONETHREE);
- strcat(filepath,&choices[8+(old_dem*2)][0]);
- strcat(filepath,".txt");
- system(filepath);
- back_drop();
- LoadView(&sec_view);
- set_sprite();
- reset_sprites();
- }
- break;
- default :
- clean_local();
- alert("Undefined button press (wowboy)\n");
- break;
- }
- }
- } while (pause==1);
- }
- }
-
- /* Clear the code display, initilise variables and Control Structures */
- /* Calls the clr compare display */
-
- void clr_code(void)
- {
- int d,z;
- int xposition = XPOS;
- int rayy = 40;
-
- back_x=let_across=pushn=stop=dtype=types=let_across=icnum=pause=ref=0;
- play=0;
- lock=locktwo=FALSE;
- fraction=trip=1;
- raynum=fnum=-1;
- for(d=0;d<FUNCMAX;d++){
- func_index[d].f_label = NULL;
- func_index[d].occured[0] = '\0';
- func_index[d].occured[1] = '\0';
- for(z=0;z<VARMAX;z++){
- ic_map[d][z].points.x = (WORD) ICSTARTX;
- ic_map[d][z].points.y = (WORD) ICSTARTY;
- ic_map[d][z].points.way = (WORD) FIN_D;
- ic_map[d][z].p_name=NULL;
- ic_map[d][z].eol.x = (WORD) ICSTARTX;
- ic_map[d][z].eol.y = (WORD) (ICSTARTY + ADJUSTY);
- ic_map[d][z].eol.way = (WORD) TERMINAL;
- }
- }
- for(d=0;d<ARRAYMAX;d++){
- for(z=0;z<MEMMAX;z++){
- array_map[d][z].p_name = NULL;
- array_map[d][z].points.x = (WORD) 0;
- array_map[d][z].points.y = (WORD) 0;
- array_map[d][z].points.way = (WORD) TERMINAL;
- array_map[d][z].eol.x = (WORD) 0;
- array_map[d][z].eol.y = (WORD) 0;
- array_map[d][z].eol.way = (WORD) TERMINAL;
- }
- }
- for(d=0;d<RECUREDEPTH;d++)
- raylist[d]=NULL;
- for(d=0;d<LEVEL;d++){
- for(z=0;z<MAXACROSS;z++){
- dis_map[d][z].p_name = NULL;
- dis_map[d][z].points.x = (WORD) CARTX;
- dis_map[d][z].points.y = (WORD) CARTY+rayy;
- dis_map[d][z].points.way = (WORD) FIN_R;
- dis_map[d][z].eol.x = (WORD) xposition;
- dis_map[d][z].eol.y = (WORD) CARTY+rayy;
- dis_map[d][z].eol.way = (WORD) TERMINAL;
- xposition+=54L;
- }
- xposition = XPOS;
- rayy+=32;
- }
- draw_modes(0xFF,&sec_rastport,A_LLGREY,A_LLGREY,JAM1);
- RectFill(&sec_rastport,282,37,619,182);
- clr_compare();
- }
-
- void clr_dem(void)
- {
- draw_modes(0xFF,&sec_rastport,A_LBLUE,A_LBLUE,JAM1);
- RectFill(&sec_rastport,0,242,639,511);
- RectFill(&sec_rastport,339,204,549,215);
- }
-
- void clr_compare(void)
- {
- draw_modes(0xFF,&sec_rastport,A_LLGREY,A_LLGREY,JAM1);
- RectFill(&sec_rastport,62,92,275,182);
- indicator_clr();
- }
-
- void indicator_clr(void){
-
- copy_object(IOFF,32,98,&sec_bitmap);
- copy_object(IOFF,32,147,&sec_bitmap);
- }
-
- void play_col(int on_off)
- {
- if (on_off==0){
- draw_modes(0xFF,&sec_rastport,A_LGREY,A_LGREY,JAM1);
- play = 0;
- }
- else{
- draw_modes(0xFF,&sec_rastport,A_LGREEN,A_LGREEN,JAM1);
- play = 1;
- }
- RectFill(&sec_rastport,Bplay.min.xc,Bplay.min.yc,Bplay.max.xc,Bplay.max.yc);
- }
-
- void pause_col(int light)
- {
- if (light==0){
- draw_modes(0xFF,&sec_rastport,A_LGREY,A_LGREY,JAM1);
- }
- else{
- draw_modes(0xFF,&sec_rastport,A_LGREEN,A_LGREEN,JAM1);
- }
- RectFill(&sec_rastport,Bpause.min.xc,Bpause.min.yc,Bpause.max.xc,Bpause.max.yc);
- }
-
- void ff_col(int led)
- {
- if (led==0){
- draw_modes(0xFF,&sec_rastport,A_LGREY,A_LGREY,JAM1);
- }
- else{
- draw_modes(0xFF,&sec_rastport,A_LGREEN,A_LGREEN,JAM1);
- }
- RectFill(&sec_rastport,Bffor.min.xc,Bffor.min.yc,Bffor.max.xc,Bffor.max.yc);
- }
-
-
- void set_sprite(void){
- if( GetSprite(&pulse_sprite, 4) != 4 ){
- clean_local();
- alert("Failed sprite1 (set_sprite)\n");
- }
- if( GetSprite(&cart_sprite, 6) != 6){
- clean_local();
- alert("Failed sprite2 (set_sprite)\n");
- }
- }
-
- void reset_sprites(void){
- change_col(0);
- MoveSprite(&sec_viewport,&pulse_sprite,602,190);
- MoveSprite(&sec_viewport,&cart_sprite,CARTX,CARTY);
- }
-
- void change_col(short action){
-
- switch(action){
- case 0 :
- SetRGB4(&sec_viewport, 24,0,0,0);
- SetRGB4(&sec_viewport, 25,2,0,15);
- SetRGB4(&sec_viewport, 26,2,0,15);
- SetRGB4(&sec_viewport, 27,2,0,15);
- SetRGB4(&sec_viewport, 28,0,0,0);
- SetRGB4(&sec_viewport, 29,7,7,7);
- SetRGB4(&sec_viewport, 30,0,0,0);
- SetRGB4(&sec_viewport, 31,9,3,2);
- break;
- case 1 :
- SetRGB4(&sec_viewport, 24,0,0,0);
- SetRGB4(&sec_viewport, 25,0,15,2);
- SetRGB4(&sec_viewport, 26,0,15,2);
- SetRGB4(&sec_viewport, 27,0,15,2);
- SetRGB4(&sec_viewport, 28,0,0,0);
- SetRGB4(&sec_viewport, 29,0,15,0);
- SetRGB4(&sec_viewport, 30,0,0,0);
- SetRGB4(&sec_viewport, 31,0,9,2);
- break;
- }
- }
-
- void killsprite(void){
-
- if(pulse_sprite.num != -1){
- FreeSprite( (WORD) pulse_sprite.num);
- pulse_sprite.num=-1;
- }
- if(cart_sprite.num != -1){
- FreeSprite( (WORD) cart_sprite.num);
- cart_sprite.num=-1;
- }
- }
-
- void clean_local(void){
- killsprite();
- al_clean();
- }
-
- void speed(void){
- if (trip==fraction){
- WaitBOVP(&sec_viewport);
- trip=1;
- }
- else {
- trip++;
- }
- }
-
- /* Forward_move and backward_move algorithms take a path, start, endpoints
- and a pointer to a sprite. (Following revisions will have this as a pointer
- to function in which animations can be utilised). The algorithms move the
- sprite along the given path. The path can contain many different points in which
- the sprite can turn off. However the sprite won't turn unless the finish given
- matches the finish in the given path. We can therefore reuse a path to specify
- different animations */
-
- void forward_move(MAPDEM travel[], MAPDEM start,MAPDEM finish, SSPTR tech){
- int count;
- BOOL end;
- WORD xmove, ymove;
-
- end=FALSE;
- count=0;
- MoveSprite(&sec_viewport,tech,start.x,start.y);
- while(end!=TRUE){
- wowboy();
- xmove=travel[count].x;
- ymove=travel[count].y;
- switch(travel[count].way){
- case ALEFT : case START_L :
- while (xmove != travel[count+1].x){
- MoveSprite(&sec_viewport,tech,xmove,ymove);
- speed(); /* Do we change the speed? */
- xmove--; /* Move sprite by one */
- wowboy(); /* Check if menu options have been pressed */
- }
- break;
- case ARIGHT : case START_R :
- while (xmove != travel[count+1].x){
- MoveSprite(&sec_viewport,tech,xmove,ymove);
- speed();
- xmove++;
- wowboy();
- }
- break;
- case AUP : case START_U :
- while (ymove != travel[count+1].y){
- MoveSprite(&sec_viewport,tech,xmove,ymove);
- speed();
- ymove--;
- wowboy();
- }
- break;
- case ADOWN : case START_D :
- while (ymove != travel[count+1].y){
- MoveSprite(&sec_viewport,tech,xmove,ymove);
- speed();
- ymove++;
- wowboy();
- }
- break;
- case FIN_U :
- if ((travel[count+1].x == finish.x) && (travel[count+1].y == finish.y)){
- while (ymove != finish.y){
- MoveSprite(&sec_viewport,tech,xmove,ymove);
- speed();
- ymove--;
- wowboy();
- }
- end=TRUE;
- }
- break;
- case FIN_D :
- if ((travel[count+1].x == finish.x) && (travel[count+1].y == finish.y)){
- while (ymove != finish.y){
- MoveSprite(&sec_viewport,tech,xmove,ymove);
- speed();
- ymove++;
- wowboy();
- }
- end=TRUE;
- }
- break;
- case FIN_L :
- if ((travel[count+1].x == finish.x) && (travel[count+1].y == finish.y)){
- while (xmove != finish.x){
- MoveSprite(&sec_viewport,tech,xmove,ymove);
- speed();
- xmove--;
- wowboy();
- }
- end=TRUE;
- }
- break;
- case FIN_R :
- if ((travel[count+1].x == finish.x) && (travel[count+1].y == finish.y)){
- while (xmove != finish.x){
- MoveSprite(&sec_viewport,tech,xmove,ymove);
- speed();
- xmove++;
- wowboy();
- }
- end=TRUE;
- }
- break;
- case TERMINAL :
- wowboy();
- break;
- default :
- clean_local();
- alert("Failed direction (forward_move)\n");
- break;
- }
- count++;
- }
- }
-
- void backward_move(MAPDEM get_road[], MAPDEM s_start,MAPDEM sprfin, SSPTR tech)
- {
- int increase;
- BOOL fin;
- WORD spritx, sprity;
-
- fin=FALSE;
- increase=0;
- spritx = get_road[increase].x;
- sprity = get_road[increase].y;
- while( (spritx!=s_start.x) || (sprity!=s_start.y) ){
- increase++;
- sprity = get_road[increase].y;
- spritx = get_road[increase].x;
- }
- MoveSprite(&sec_viewport,tech,s_start.x,s_start.y);
- while(increase > 0){
- wowboy();
- switch(get_road[increase-1].way){
- case ALEFT : case FIN_L : case START_L :
- while (spritx != get_road[increase-1].x){
- MoveSprite(&sec_viewport,tech,spritx,sprity);
- speed();
- spritx++;
- wowboy();
- }
- break;
- case ARIGHT : case FIN_R : case START_R :
- while (spritx != get_road[increase-1].x){
- MoveSprite(&sec_viewport,tech,spritx,sprity);
- speed();
- spritx--;
- wowboy();
- }
- break;
- case AUP : case FIN_U : case START_U :
- while (sprity != get_road[increase-1].y){
- MoveSprite(&sec_viewport,tech,spritx,sprity);
- speed();
- sprity++;
- wowboy();
- }
- break;
- case ADOWN : case FIN_D : case START_D :
- while (sprity != get_road[increase-1].y){
- MoveSprite(&sec_viewport,tech,spritx,sprity);
- speed();
- sprity--;
- wowboy();
- }
- break;
- case TERMINAL :
- wowboy();
- break;
- default :
- clean_local();
- alert("Failed direction (backward_move)\n");
- break;
- }
- increase--;
- }
- }
-
- /* Comp_wrt writes text to the compare display. torite is
- the number of spaces across the text should be printed. */
-
- void comp_wrt(int torite,char *words){
- int cmpmax=0;
-
- /* Make sure we haven't got a NULL string */
- if(words){
- cmpmax=strlen(words);
- if( (torite+cmpmax) <= COMPWIDTH) { /* Check width is within Max Range */
- if (locktwo==TRUE) /* Switch highlight off if on */
- compare_line();
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- writetxt((64+(torite*LETWIDTH)),168,&sec_rastport,words);
- compare_line();
- }
- }
- }
-
- /* comp_scroll, scrolls by one line the information in the compare display */
-
- void comp_scroll(void){
- wowboy();
- if(stop==0){
- if (locktwo==TRUE) compare_line();
- SetBPen(&sec_rastport,A_LLGREY);
- ScrollRaster(&sec_rastport,0,UP,62,(182-8*UP),275,182);
- }
- }
-
- PLAN get_dest(char *destname){
- PLAN dest;
-
- let_across=0;
- plan_clear(dest);
- whatisit(destname);
- dest = get_splan(0);
- whatisit(destname);
- back_x = realindex;
- dtype = types;
- if(dest.p_name==NULL){
- clean_local();
- alert("Failed to locate dest coords (a_intass)\n");
- }
- if(strlen(dest.p_name)>=MAXILEN ){
- clean_local();
- alert("The length of the variable name exceeds limits (a_intass)\n");
- }
- strcpy(back_name,dest.p_name);
- get_road(dest);
- comp_wrt(let_across,destname);
- if(destname!=NULL)
- let_across += strlen(destname)+1;
- else
- let_across++;
- comp_wrt(let_across,"=");
- let_across+=2;
- al_clean();
- backward_move(pathone,pathone[8],pathone[0],&pulse_sprite);
- return dest;
- }
-
- int get_src(char *comname){
-
- PLAN source;
- int total=0;
- int deal=0;
- int ct =0;
- int lt;
- char numname[LETWIDTH];
- char sad[2]={'\0','\0'};
-
- plan_clear(source);
- whatisit(comname);
- source=get_splan(deal);
- whatisit(comname);
- total=source.worth.number;
- if(source.p_name==NULL){
- clean_local();
- alert("Failed to locate source coords (get_src)\n");
- }
- get_road(source);
- itochar(source.worth.number,numname);
- comp_wrt(let_across,numname);
- if(numname!=NULL)
- let_across += strlen(numname)+1;
- else
- let_across++;
- deal++;
- while( (argument[deal-1].sign[0]!='\0') && (deal<ARGNUM) ){
- source=get_splan(deal);
- whatisit(comname);
- lt=calc(total,argument[deal-1].sign[0],source.worth.number);
- total=lt;
- if(source.p_name==NULL){
- clean_local();
- alert("Failed to locate source coords (get_src)\n");
- }
- get_road(source);
- switch(argument[deal-1].sign[0]){
- case '/' :
- sad[0]='/';
- break;
- case '*' :
- sad[0]='*';
- break;
- case '+' :
- sad[0]='+';
- break;
- case '-' :
- sad[0]='-';
- break;
- default :
- clean_local();
- alert("Failed to identify sign (get_src)\n");
- break;
- }
- comp_wrt(let_across,sad);
- let_across+=2;
- itochar(source.worth.number,numname);
- comp_wrt(let_across,numname);
- if(numname!=NULL)
- let_across += strlen(numname)+1;
- else
- let_across++;
- deal++;
- }
- al_clean();
- return total;
- }
-
-
- int calc(int left,char how,int right){
- int part;
-
- switch(how){
- case '/' :
- part = left / right;
- break;
- case '*' :
- part = left * right;
- break;
- case '+' :
- part = left + right;
- break;
- case '-' :
- part = left - right;
- break;
- default :
- clean_local();
- alert("Undefined symbol In (calc)\n");
- break;
- }
- return part;
- }
-
- void put_road(PLAN route){
- WORD pix_x,pix_y;
- char obval[LETWIDTH];
-
- change_col( (short) PUT);
- switch(dtype){
- case ICVAR :
- pix_x=route.points.x-ADJUSTX;
- pix_y=route.points.y;
- itochar(route.worth.number,obval);
- backone[1].way=ARIGHT;
- backone[2]=route.points;
- backone[3]=route.eol;
- forward_move(backone,backone[0],backone[3],&pulse_sprite);
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- copy_object(VAR,pix_x+2,pix_y,&sec_bitmap);
- writetxt(pix_x+4,pix_y+39,&sec_rastport,back_name);
- writetxt(pix_x+4,pix_y+54,&sec_rastport,obval);
- chill((STILL/2)/fraction);
- backward_move(backone,backone[3],backone[0],&pulse_sprite);
- backward_move(pathone,pathone[8],pathone[0],&pulse_sprite);
- break;
- case ICRAY :
- pix_x=route.eol.x;
- pix_y=YPOS;
- backone[1].way = FIN_L;
- backone[2].x=38;
- backone[2].y=236;
- backone[2].way=TERMINAL;
- pathfour[1]=route.points;
- pathfour[2]=route.eol;
- forward_move(backone,backone[0],backone[2],&pulse_sprite);
- forward_move(pathfour,pathfour[0],pathfour[2],&cart_sprite);
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- copy_object(IAR,pix_x,pix_y,&sec_bitmap);
- itochar(back_x,obval);
- writetxt(pix_x+2,pix_y+19,&sec_rastport,obval);
- itochar(route.worth.number,obval);
- writetxt(pix_x+2,pix_y+9,&sec_rastport,back_name);
- writetxt(pix_x+27,pix_y+9,&sec_rastport,obval);
- chill((STILL/2)/fraction);
- backward_move(pathfour,pathfour[2],pathfour[0],&cart_sprite);
- backward_move(backone,backone[2],backone[0],&pulse_sprite);
- backward_move(pathone,pathone[8],pathone[0],&pulse_sprite);
- break;
- default :
- clean_local();
- alert("ERROR In (put_road)\n");
- break;
- }
- }
-
- void a_func(char *fname, int f_hlp){
-
- if (stop==0){
- icnum=0;
- fnum++;
- if (fnum>=FUNCMAX){
- clean_local();
- alert("Maximum functions exceeded (a_func)\n");
- }
- /* How many times does function exist? */
- func_index[fnum].occured[0]=check_index(fname);
- func_index[fnum].f_label = fname;
- func_index[fnum].occured[1]='\0';
- clr_dem();
- copy_object(HOLE,8L, 242L, &sec_bitmap);
- go_code(f_hlp);
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- Move(&sec_rastport,rect[0],rect[1]);
- /* PolyDraw(&sec_rastport,(WORD) 5,rect); */
- writetxt(341,212,&sec_rastport,func_index[fnum].f_label);
- writetxt(540,212,&sec_rastport,func_index[fnum].occured);
- }
- }
-
- /* a_rayini Initilises position and value data for an integer array */
-
- void a_irayini(int first[],char *rayname,int members, int iray_hlp){
- int r;
-
- go_code(iray_hlp);
- if(stop==0){
- raynum++; /* Next Array Please */
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- if( (members>MEMMAX) || (raynum>=ARRAYMAX) ){
- clean_local();
- alert("Exceeded Max Members-200 Or Exceeded Ray Depth 1 (a_rayini)\n");
- }
- for(r=0;r<members;r++){
- array_map[raynum][r].points.x = (WORD) 0;
- array_map[raynum][r].points.y = (WORD) 0;
- array_map[raynum][r].points.way = (WORD) FIN_R;
- array_map[raynum][r].p_name = rayname;
- array_map[raynum][r].eol.x = (WORD) 0;
- array_map[raynum][r].eol.y = (WORD) 0;
- array_map[raynum][r].eol.way = (WORD) TERMINAL;
- array_map[raynum][r].worth.number = first[r];
- }
- r=0;
- while( (r<MAXACROSS) && (r<members) ){
- engrave_iray(r,r,0);
- r++;
- }
- chill((STILL/2)/fraction);
- }
- }
-
- /* engrave_iray: Prints all aspects of an array graphic. Set
- draw_modes before calling this function */
-
- void engrave_iray(int start, int raydex, int depth){
- char memnum[LETWIDTH];
- int across;
-
- dis_map[depth][start].p_name = array_map[raynum][raydex].p_name;
- dis_map[depth][start].worth.number = array_map[raynum][raydex].worth.number;
- across = dis_map[depth][start].eol.x;
- copy_object(IAR,across,YPOS,&sec_bitmap); /* Print array graphic */
- itochar(raydex,memnum); /* Convert index */
- writetxt(across+2,YPOS+19,&sec_rastport,memnum);
- /* Print arrays index */
- itochar(dis_map[depth][start].worth.number,memnum);
- writetxt(across+2,YPOS+9,&sec_rastport,dis_map[depth][start].p_name);
- /* Print arrays name */
- writetxt(across+27,YPOS+9,&sec_rastport,memnum);
- /* Print arrays value */
- }
-
-
- void a_intini(int ivalue,char *iname, int i_hlp){
- WORD across, down;
-
- go_code(i_hlp);
- if(stop==0){
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- across=ic_map[fnum][icnum].points.x-ADJUSTX;
- down=ic_map[fnum][icnum].points.y;
- ic_map[fnum][icnum].p_name=iname;
- ic_map[fnum][icnum].worth.number=ivalue;
- engrave_int(icnum);
- icnum++;
- if (icnum>=VARMAX){
- clean_local();
- alert("Maximum number of ints/chars exceeded\n");
- }
- ic_map[fnum][icnum].points.x = (WORD) (across + NEXTVAR + ADJUSTX);
- ic_map[fnum][icnum].points.y = (WORD) down;
- ic_map[fnum][icnum].points.way = (WORD) FIN_D;
- ic_map[fnum][icnum].eol.x = (WORD) (across + NEXTVAR + ADJUSTX);
- ic_map[fnum][icnum].eol.y = (WORD) (down+ADJUSTY);
- ic_map[fnum][icnum].eol.way = (WORD) TERMINAL;
- }
- }
-
- /* engrave_int: Print all aspects of a variable graphic */
-
- void engrave_int(int idex){
- char keeper[LETWIDTH];
- WORD shuffle_x, shuffle_y;
-
- shuffle_x = ic_map[fnum][idex].points.x-ADJUSTX;
- shuffle_y = ic_map[fnum][icnum].points.y;
-
- copy_object(VAR,shuffle_x+2,shuffle_y,&sec_bitmap); /* Print Main Graphic */
- itochar(ic_map[fnum][idex].worth.number,keeper);
- writetxt(shuffle_x+4,shuffle_y+39,&sec_rastport,ic_map[fnum][idex].p_name);
- /* Print Vars Name */
- writetxt(shuffle_x+4,shuffle_y+54,&sec_rastport,keeper);
- /* Print Vars value */
-
- }
-
-
- void a_intass(char *dname, char *sname, int ia_hlp){
- VALUE new;
- short ohno=0;
- PLAN arrive;
-
- go_code(ia_hlp);
- if(stop==0){
- arrive=get_dest(dname);
- new.number=get_src(sname);
- comp_scroll();
- if(stop==0){
- ohno=putback(back_name,back_x,new);
- if(ohno==0){
- clean_local();
- alert("Failed to assign new value (a_intass)\n");
- }
- arrive.worth.number=new.number;
- put_road(arrive);
- }
- }
- }
-
- void a_iraypas(char *nrname, int irp_hlp){
- int yoyo=0;
-
- go_code(irp_hlp);
- if(stop==0){
- if(array_map[raynum][0].p_name==NULL){
- clean_local();
- alert("Array has no name (a_iraypas)\n");
- }
- raylist[pushn] = array_map[raynum][0].p_name; /* Put name on stack */
- pushn++;
- if(pushn>=RECUREDEPTH){
- clean_local();
- alert("Name list exceeded limit (a_iraypas)\n");
- }
- /* Rename Present Array */
- while( (array_map[raynum][yoyo].p_name!=NULL) && (yoyo<MEMMAX) ){
- array_map[raynum][yoyo].p_name=nrname;
- yoyo++;
- }
- /* Draw Renamed Array */
- yoyo=0;
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- while( (yoyo<MAXACROSS) && (array_map[raynum][yoyo].p_name!=NULL) ){
- engrave_iray(yoyo,yoyo,0);
- yoyo++;
- }
- }
- }
-
-
- /* question takes a string and proceeds to write it on the test display.
- It first parses the string, gets the first arguments details, types
- them to the display, then does the same for the second argument,
- afterwhich it tests them and displays true or false. Must remember
- that get_splan returns rec, therefore only one PLAN at a time. */
-
- void question(char *onlytwo){
- int bee,wasp,click;
- PLAN predone;
- char prname[LETWIDTH];
- SHORT nxt = 0;
- SHORT look = 0;
-
- click=0;
- whatisit(onlytwo);
- if( (argument[nxt].sign[0]=='-') && (argument[nxt].dexrep==NULL) ){
- /* Got a negative first argument */
- nxt++;
- look=1;
- predone=get_splan(nxt);
- bee=predone.worth.number * -1;
- whatisit(onlytwo); /* Restantiate argument[] get_splan may have altered it */
- }
- else{
- /* Normal first argument */
- predone=get_splan(nxt);
- bee=predone.worth.number;
- look=0;
- whatisit(onlytwo);
- }
- if(predone.p_name==NULL){
- clean_local();
- alert("Failed to locate predone coords (question)\n");
- }
- get_road(predone);
- itochar(bee,prname);
- comp_wrt(click,prname);
- if(prname[0]!=NULL)
- click += strlen(prname)+1;
- else
- click++;
- /* Fix for a Test(thing) */
- if( (argument[nxt].sign[0]!='\0') || (argument[nxt].sign[1]!='\0') ){
- comp_wrt(click,argument[0].sign);
- click += strlen(argument[0].sign) + 1;
- predone=get_splan(nxt);
- backward_move(pathone,pathone[8],pathone[0],&pulse_sprite);
- whatisit(onlytwo);
- }
- if( (argument[nxt].sign[0]=='\0') && (argument[nxt].sign[1]=='\0') ){
- /* Assume we are dealing with a test(thing) */
- /* Argument sign fix */
- argument[nxt].sign[0]='N';
- argument[nxt].sign[1]='O';
- argument[nxt].sign[2]='\0';
- }
- else{
- /* Have a second argument */
- nxt++;
- if( (argument[nxt].sign[0]=='-') && (argument[nxt].dexrep==NULL) ){
- /* Got a negative second argument */
- nxt++;
- predone=get_splan(nxt);
- wasp=predone.worth.number * -1;
- whatisit(onlytwo);
- }
- else{
- /* Normal */
- predone=get_splan(nxt);
- wasp=predone.worth.number;
- whatisit(onlytwo);
- }
- get_road(predone);
- itochar(wasp,prname);
- comp_wrt(click,prname);
- }
- if(argument[look].sign[1] != '='){
- switch(argument[look].sign[0]){
- case '>' :
- if (bee > wasp)
- copy_object(ION,32,98,&sec_bitmap);
- else
- copy_object(ION,32,147,&sec_bitmap);
- break;
- case '<' :
- if (bee < wasp)
- copy_object(ION,32,98,&sec_bitmap);
- else
- copy_object(ION,32,147,&sec_bitmap);
- break;
- case 'N' :
- if(bee)
- copy_object(ION,32,98,&sec_bitmap);
- else
- copy_object(ION,32,147,&sec_bitmap);
- break;
- default :
- clean_local();
- alert("Unrecognised sign (question a)\n");
- }
- }
- else{
- switch(argument[look].sign[0]){
- case '=' :
- if (bee == wasp)
- copy_object(ION,32,98,&sec_bitmap);
- else
- copy_object(ION,32,147,&sec_bitmap);
- break;
- case '!' :
- if (bee != wasp)
- copy_object(ION,32,98,&sec_bitmap);
- else
- copy_object(ION,32,147,&sec_bitmap);
- break;
- case '>' :
- if (bee >= wasp)
- copy_object(ION,32,98,&sec_bitmap);
- else
- copy_object(ION,32,147,&sec_bitmap);
- break;
- case '<' :
- if (bee <= wasp)
- copy_object(ION,32,98,&sec_bitmap);
- else
- copy_object(ION,32,147,&sec_bitmap);
- break;
- default :
- clean_local();
- alert("Unrecognised sign (question b)\n");
- }
- }
- whatisit(onlytwo);
- chill( STILL/fraction);
- indicator_clr();
- backward_move(pathone,pathone[8],pathone[0],&pulse_sprite);
- }
-
-
- void a_intcomp(char *f_arg , int ic_hlp)
- {
-
- go_code(ic_hlp);
- if(stop==0){
- question(f_arg);
- comp_scroll();
- al_clean();
- }
- }
-
-
- void a_show(int sh_hlp){
- go_code(sh_hlp);
- chill((STILL/5)/fraction);
- }
-
- /* a_endfunc End a function and restore display of previous function */
-
- void a_endfunc(char *ename, int e_hlp){
- int abacus=0;
-
- /* DOESN'T USE ename */
- go_code(e_hlp);
- /* Has the stop button been pressed? */
- if(stop==0){
- /* Clear the function parameters */
- func_index[fnum].f_label = NULL;
- func_index[fnum].occured[0] = '\0';
- func_index[fnum].occured[1] = '\0';
- for(abacus=0;abacus<VARMAX;abacus++){
- ic_map[fnum][abacus].points.x = (WORD) ICSTARTX;
- ic_map[fnum][abacus].points.y = (WORD) ICSTARTY;
- ic_map[fnum][abacus].points.way = (WORD) FIN_D;
- ic_map[fnum][abacus].p_name=NULL;
- ic_map[fnum][abacus].eol.x = (WORD) ICSTARTX;
- ic_map[fnum][abacus].eol.y = (WORD) (ICSTARTY + ADJUSTY);
- ic_map[fnum][abacus].eol.way = (WORD) TERMINAL;
- }
- fnum--; /* Function down */
- pushn--; /* Name list down */
- /* Rename array */
- if(pushn>=0){
- abacus=0;
- while( (array_map[raynum][abacus].p_name!=NULL) && (abacus<MEMMAX) ){
- array_map[raynum][abacus].p_name=raylist[pushn];
- abacus++;
- }
- }
- /* Calculate function reference to restore */
- if(fnum!=-1){
- clr_dem(); /* Clear the demonstration Display */
- /* Restore Previous Function Display */
- draw_modes(0xFF,&sec_rastport,A_BLACK,A_BLACK,JAM1);
- copy_object(HOLE,8L, 242L, &sec_bitmap);
- writetxt(341,212,&sec_rastport,func_index[fnum].f_label);
- writetxt(540,212,&sec_rastport,func_index[fnum].occured);
- abacus=0;
- while(ic_map[fnum][abacus].p_name!=NULL){
- /* Restore Variables */
- engrave_int(abacus);
- ++abacus;
- }
- abacus=0;
- if(raynum<0){
- clean_local();
- alert("Failed to index array_map (a_endfunc)\n");
- }
- while( (array_map[raynum][abacus].p_name!=NULL) && (abacus<MAXACROSS) ){
- /* Restore Array */
- engrave_iray(abacus,abacus,0);
- ++abacus;
- }
- }
- }
- }
-